const db = require('../conn.js');
const r = require('../err.js');
module.exports = (app)=>{
	app.route('/node/reg')
		.get((req, res)=>{
			let query = req.query;
			if (! (query.name && query.password && query.tel)) {
				res.json(r.error(1));
				return;
			}
			if (query.name.includes('@')) {
				res.json(r.error(100,'用户名不能包含@'));
				return;
			}
			(async function work(){
				try{
					let user = await db.get('users').find({name:query.name});
					if (user && user.name) {
						res.json(r.error(3)); 
						return;
					}
					let tmp = await db.get('users').insert(query);
					res.json(r.success(''));
				}catch(e){
					console.log(e);
					res.json(r.error(500,e.toString()));
				}
			})();
		});
};
